/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package guiforms;

import controlers.MainControler;
import javax.swing.JOptionPane;
/**
 *
 * @author Tasos
 */
public class ManageMyProfile extends javax.swing.JFrame {
private String customerID = "";
MainControler ctrl = new MainControler(); //tha ginei xrhsh toy MainControler
    /**
     * Creates new form ManageMyProfile - Forma Epeksergasias stoixeiwwn pelath
     * H parousa forma xrhsimopoieite toso gia thn allagh stoixeiwn apo yparxontes
     * pelates oso kai gia thn dimioyrgia neou account
     */
    public ManageMyProfile() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextFieldName = new javax.swing.JTextField();
        jTextFieldSurname = new javax.swing.JTextField();
        jTextFieldAddress = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        btnSave = new javax.swing.JButton();
        btnDeleteAccount = new javax.swing.JButton();
        btnPasswordChange = new javax.swing.JButton();
        btnViewChecks = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jTextFieldCreditCard = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jTextFieldName.setText("Name");
        jTextFieldName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldNameActionPerformed(evt);
            }
        });

        jTextFieldSurname.setText("Surname");

        jTextFieldAddress.setText("Address");

        jLabel1.setText("Όνομα");

        jLabel2.setText("Επώνυμο");

        jLabel3.setText("Διευθυνση");

        jTextField4.setEditable(false);
        jTextField4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jTextField4.setText("ΕΠΕΞΕΡΓΑΣΙΑ ΣΤΟΙΧΕΙΩΝ");

        btnSave.setText("Αποθηκευση Αλλαγών");
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });

        btnDeleteAccount.setText("Διαγραφή λογαριασμού");
        btnDeleteAccount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteAccountActionPerformed(evt);
            }
        });

        btnPasswordChange.setText("Αλλαγή Κωδικου");
        btnPasswordChange.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPasswordChangeActionPerformed(evt);
            }
        });

        btnViewChecks.setText("Εμφανιση Επιταγών");
        btnViewChecks.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnViewChecksActionPerformed(evt);
            }
        });

        jTextFieldCreditCard.setText("Card Number");
        jTextFieldCreditCard.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldCreditCardActionPerformed(evt);
            }
        });

        jLabel4.setText("Credit Card");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(btnPasswordChange, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnSave, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(btnDeleteAccount, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnViewChecks, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(95, 95, 95)
                        .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSeparator1)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(jLabel3))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 36, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldName)
                    .addComponent(jTextFieldSurname, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE)
                    .addComponent(jTextFieldAddress, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE)
                    .addComponent(jTextFieldCreditCard, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(41, 41, 41))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jTextFieldAddress, jTextFieldName, jTextFieldSurname});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(9, 9, 9)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldSurname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldCreditCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnPasswordChange)
                    .addComponent(btnViewChecks))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSave)
                    .addComponent(btnDeleteAccount))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jTextFieldAddress, jTextFieldCreditCard, jTextFieldName, jTextFieldSurname});

        pack();
    }// </editor-fold>//GEN-END:initComponents

//thetei to CustomerID kai arxikopoiei ta pedia ths formas    
public void setCustomerID(String cid)
{
customerID=cid;  //to Customer ID
//Arxikopoioume ta pedia ths formas analoga me ta stoixeia toy pelath me
//xrhsh toy MainControler, edw diaxwrizetai arxika h periptwsh eggrafhs 
//neou pelath h enhmerwshs yparxontos pelath
if(!customerID.equals("new customer")){    
jTextFieldName.setText(ctrl.findCustomerByCard(cid).getFirstName());
jTextFieldSurname .setText(ctrl.findCustomerByCard(cid).getLastName());
jTextFieldAddress.setText(ctrl.findCustomerByCard(cid).getAddress());
jTextFieldCreditCard.setText(ctrl.findCustomerByCard(cid).getCreditcard());
}
else //An exoume neo pelath kapoia buttons apenergopoiounte
{
btnDeleteAccount.setEnabled(false);
btnPasswordChange.setEnabled(false);
btnViewChecks.setEnabled(false);
}    
}

    
    //Event Handler toy Button provolhs epitagwn 
    private void btnViewChecksActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnViewChecksActionPerformed
    CheckListForm cl = new CheckListForm(); //nea forma
    cl.setCustomerId(customerID); //enhmerwsh ths me to customer ID
    cl.setVisible(true);  //provolh
    }//GEN-LAST:event_btnViewChecksActionPerformed

    //Event Handler toy Button allaghs password 
    private void btnPasswordChangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPasswordChangeActionPerformed
    ChangePasswordForm cp = new ChangePasswordForm(); //nea forma llaghs kwdikou
    cp.setCustomerID(customerID);  //enhmerwsh me to Customer ID
    cp.setVisible(true); //provolh
    }//GEN-LAST:event_btnPasswordChangeActionPerformed

    
    
//Event Handler toy Koumpiou diagrafhs Account    
    private void btnDeleteAccountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteAccountActionPerformed
//Dimiourgia mynhmatos proidopoihshs
int validate = JOptionPane.showConfirmDialog(this 
                ,"Αυτη η ενεργεια θα διαγραψει τον λογαρισαμό σας,\n"
                +"και θα κλησει το πρόγραμμα."+ " Θελετε να συνεχίσετε;" 
                ,"Διαγραφή Λογαριασμού!!!", JOptionPane.WARNING_MESSAGE
                , JOptionPane.OK_CANCEL_OPTION);
//An dwthei OK apo ton pelath
if (validate==0)
{
//me thn xrhsh toy Main Controler diagrafete o pelaths
ctrl.removeCustomer(customerID);   
//kai ksefwrtwnei h forma (me klisimo toy programmatos)
this.dispose();
}
    }//GEN-LAST:event_btnDeleteAccountActionPerformed

    private void jTextFieldNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldNameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldNameActionPerformed

    //Event Handler toy koumpiou Apothikeysh allagwn
    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
     //An den prokite gia neo pelath
     if(!customerID.equals("new customer")){
     //prospathia enhmerwshs twn stoixeiwn me xrhsh toy Main Controler
     if(ctrl.updateCustomer(customerID, jTextFieldAddress.getText(), jTextFieldName.getText(), jTextFieldSurname.getText(),jTextFieldCreditCard.getText()))
     //Enhmerwsh pelath gia epityxia
     JOptionPane.showMessageDialog(this,"Τα στοιχεια ενημερώθηκαν επιτυχώς","Αναφορά",JOptionPane.WARNING_MESSAGE);
     else
     //H apotyxia
     JOptionPane.showMessageDialog(this,"Σφάλμα κατα την ενημέρωση των στοιχείων","Σφάλμα",JOptionPane.WARNING_MESSAGE);
     }
     else //an afora neo pelath
     {
     //prosthiki toy me xrhsh toy MainControler
     ctrl.addCustomer(jTextFieldAddress.getText(),jTextFieldName.getText(), jTextFieldSurname.getText(),jTextFieldCreditCard.getText());
     }
     //Klisimo formas
     this.dispose();
    }//GEN-LAST:event_btnSaveActionPerformed

    private void jTextFieldCreditCardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldCreditCardActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldCreditCardActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ManageMyProfile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ManageMyProfile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ManageMyProfile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ManageMyProfile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ManageMyProfile().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnDeleteAccount;
    private javax.swing.JButton btnPasswordChange;
    private javax.swing.JButton btnSave;
    private javax.swing.JButton btnViewChecks;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextFieldAddress;
    private javax.swing.JTextField jTextFieldCreditCard;
    private javax.swing.JTextField jTextFieldName;
    private javax.swing.JTextField jTextFieldSurname;
    // End of variables declaration//GEN-END:variables
}
